package com.feeyo.groundservice.composewidget.view.dlg

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.wrapContentHeight
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.window.Dialog
import androidx.compose.ui.window.DialogProperties
import com.feeyo.groundservice.composewidget.R
import com.feeyo.groundservice.composewidget.util.dimenToDp

/**
 *作者：QLH on 2024-08-23
 *描述：基础弹框
 */


/**基础弹框**/
@Composable
fun CustomBaseDlg(
    isShow: Boolean,
    onDismissRequest: () -> Unit = {},
    dismissOnBackPress: Boolean = true,
    dismissOnClickOutside: Boolean = true,
    bgColor: Color = Color.White,
    titleContent: @Composable ColumnScope.() -> Unit = {},
    msgContent: @Composable ColumnScope.() -> Unit = {},
    btnContent: @Composable ColumnScope.() -> Unit = {},
) {
    if (isShow) {
        Dialog(
            onDismissRequest = { onDismissRequest() },
            properties = DialogProperties(
                dismissOnBackPress = dismissOnBackPress,
                dismissOnClickOutside = dismissOnClickOutside,
                usePlatformDefaultWidth = false
            )
        ) {
            Card(
                modifier = Modifier
                    .fillMaxWidth(0.8f)
                    .wrapContentHeight(),
                shape = RoundedCornerShape(R.dimen.d6.dimenToDp()),
                elevation = CardDefaults.cardElevation(R.dimen.d2.dimenToDp()),
                colors = CardDefaults.elevatedCardColors(containerColor = bgColor),
            ) {
                Column(
                    modifier = Modifier.fillMaxWidth()
                ) {
                    titleContent()
                    msgContent()
                    btnContent()
                }
            }
        }
    }
}